<xsl:stylesheet version="2.0" xmlns:foo="http://something" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml">

	<xsl:import href="/apps/engine/utils/translate_fct.xsl"/>

	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:value-of select="/data/appname"/>
					<xsl:if test="/data/copName != ''"> - <xsl:value-of select="/data/copName"/>
					</xsl:if>
				</title>
				<link rel="stylesheet" type="text/css" href="/views/css/preferences.css" />
				<link rel="stylesheet" type="text/css" href="/views/cssadds/orbeon-forms.css" />
				<xforms:model>
					<xforms:instance src="input:instance"/>
					<xforms:bind nodeset="password/old" relevant="../new != '' and ../new = ../confirm" constraint="../new = '' or . != ''"/>
					<xforms:bind nodeset="password/confirm" constraint=". = ../new"/>
					<xforms:bind nodeset="password/new" constraint="string-length(.) > 7 or .=''"/>
					<!--<xforms:bind nodeset="password/old" constraint="../new = '' or . != ''"/>-->					
					<xforms:submission id="main-submission" method="post" replace="all" mode="asynchronous" resource="/portal/preferences/"/>
				</xforms:model>
			</head>
			<body>
				<xsl:variable name="dict" select="/data/translation"/>
				<div id="header">
					<div id="organization_name">
						<xsl:value-of select="/data/copName"/>
					</div>

					<img id="logo" src="../../views/img/logo.png"/>
					<a id="header_action" href="/">
						<xsl:value-of select="foo:translate('Back to the portal', $dict)"/>
					</a>

					<div id="control">
						<ul id="user_info">
							<li>
								<xsl:value-of select="/data/username"/>
							</li>
						</ul>
						<ul>
							<xsl:if test="/data/widgetManagement = 'true'">
								<li>
									<a id="administration" href="/admin/main/">
										<xsl:value-of select="foo:translate('Administration', $dict)"/>
									</a>
								</li>
							</xsl:if>
							<li>
								<a id="preferences" href="/portal/preferences/">
									<xsl:value-of select="foo:translate('My preferences', $dict)"/>
								</a>
							</li>
							<li>
								<a id="help" href="../../index.php/help/index">
									<xsl:value-of select="foo:translate('Online help', $dict)"/>
								</a>
							</li>
						</ul>

						<ul>
							<li>
								<a id="logout" href="../../index.php/users/logout">
									<xsl:value-of select="foo:translate('Logout', $dict)"/>
								</a>
							</li>
						</ul>
					</div>
				</div>
				<div id="content">
					<div class="section">
						<h1>
							<xsl:value-of select="foo:translate('My preferences', $dict)"/>
						</h1>

						<div id="user_preferences">
							<xsl:if test="/data/error != ''">
								<div id="error">
									<xsl:value-of select="foo:translate(/data/error, $dict)"/>
								</div>
							</xsl:if>
							<xsl:if test="/data/message != ''">
								<div id="message">
									<xsl:value-of select="foo:translate(/data/message, $dict)"/>
								</div>
							</xsl:if>

							<fieldset id="password_section">
								<legend>
									<xsl:value-of select="foo:translate('Identifiers', $dict)"/>
								</legend>

								<div class="form_line">
									<xforms:secret ref="password/new" incremental="true">
										<xforms:label>
											<xsl:value-of select="foo:translate('New password', $dict)"/>
										</xforms:label>
										<xforms:alert>
											<xsl:value-of select="foo:translate('The new password you provided is too short and must be at least composed of 8 characters.', $dict)"/>
										</xforms:alert>
									</xforms:secret>
								</div>
								<div class="form_line">
									<xforms:secret ref="password/confirm" incremental="true">
										<xforms:label>
											<xsl:value-of select="foo:translate('Confirm new password', $dict)"/>
										</xforms:label>
										<xforms:alert>
											<xsl:value-of select="foo:translate('The new and confirmation passwords are different. Please try again.', $dict)"/>
										</xforms:alert>
									</xforms:secret>
								</div>
								<div class="form_line">
									<xforms:secret ref="password/old" incremental="true">
										<xforms:label>
											<xsl:value-of select="foo:translate('Old password', $dict)"/>
										</xforms:label>
										<xforms:alert>
											<xsl:value-of select="foo:translate('Please provide a password.', $dict)"/>
										</xforms:alert>
									</xforms:secret>
								</div>
							</fieldset>

							<fieldset>
								<legend>
									<xsl:value-of select="foo:translate('Language', $dict)"/>
								</legend>
								<xforms:select1 ref="lang" appearance="minimal">
									<xforms:label>
										<xsl:value-of select="foo:translate('User interface language', $dict)"/>
									</xforms:label>
									<xforms:item>
										<xforms:label>English</xforms:label>
										<xforms:value>en</xforms:value>
									</xforms:item>
									<xforms:item>
										<xforms:label>Fran&#231;ais</xforms:label>
										<xforms:value>fr</xforms:value>
									</xforms:item>

								</xforms:select1>
							</fieldset>

							<div class="additional_info">
								<xsl:value-of select="foo:translate('The field ''Old password'' must be filled in only if you want to change your password.', $dict)"/>
							</div>
							<div class="submit">
								<xforms:submit submission="main-submission">
									<xforms:label>
										<xsl:value-of select="foo:translate('Save', $dict)"/>
									</xforms:label>
								</xforms:submit>
								<xforms:trigger>
									<xforms:label>
										<xsl:value-of select="foo:translate('Reset', $dict)"/>
									</xforms:label>
									<xforms:action xmlns:ns1="http://www.w3.org/2001/xml-events" ns1:event="DOMActivate">
										<xforms:setvalue ref="password/new"/>
										<xforms:setvalue ref="password/old"/>
										<xforms:setvalue ref="password/confirm"/>
									</xforms:action>
								</xforms:trigger>
							</div>
						</div>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>